/*
*  Copyright 2019-2023 oyun
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/package com.oyun.modules.hpPicture.service.impl;

import com.oyun.modules.hpPicture.domain.HpPicture;
import FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oyun.modules.hpPicture.service.HpPictureService;
import com.oyun.modules.hpPicture.domain.vo.HpPictureQueryCriteria;
import com.oyun.modules.hpPicture.mapper.HpPictureMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import PageResult;

/**
* @description 服务实现
* @author aoyun
* @date 2024-04-26
**/
@Service
@RequiredArgsConstructor
public class HpPictureServiceImpl extends ServiceImpl<HpPictureMapper, HpPicture> implements HpPictureService {

    private final HpPictureMapper hpPictureMapper;

    @Override
    public PageResult<HpPicture> queryAll(HpPictureQueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(hpPictureMapper.findAll(criteria, page));
    }

    @Override
    public List<HpPicture> queryAll(HpPictureQueryCriteria criteria){
        return hpPictureMapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(HpPicture resources) {
        save(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(HpPicture resources) {
        HpPicture hpPicture = getById(resources.getId());
        hpPicture.copy(resources);
        saveOrUpdate(hpPicture);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        removeBatchByIds(ids);
    }

    @Override
    public void download(List<HpPicture> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (HpPicture hpPicture : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put(" hpId",  hpPicture.getHpId());
            map.put(" pathImage",  hpPicture.getPathImage());
            map.put(" createBy",  hpPicture.getCreateBy());
            map.put(" createTime",  hpPicture.getCreateTime());
            map.put(" updateBy",  hpPicture.getUpdateBy());
            map.put(" updateTime",  hpPicture.getUpdateTime());
            map.put(" remark",  hpPicture.getRemark());
            map.put(" status",  hpPicture.getStatus());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}